<template>
	<view class="wrap">
		<u-waterfall v-model="flowList" idKey="idx" ref="uWaterfall">
			<template v-slot:left="{leftList}">
				<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="go(item)">
					<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
					<u-lazy-load threshold="-450" border-radius="10" :image="item.cover" :index="index"
						v-if="item.cover"></u-lazy-load>

					<view v-if="item.classifyName">
						<view class="u-font-weight u-margin-bottom-20 u-margin-top-20">
							{{item.title}}
						</view>
						<view>
							<u-icon name="bookmark-fill" color="#2979FF"></u-icon>
							<text class="u-font-xs  u-margin-left-10 $u-type-info">{{item.classifyName}}</text>
						</view>
					</view>

                    <!-- 效果图全景 -->
					<view v-if="item.city">
						<view class="demo-title">
							{{item.title}}
						</view>
						<view class="demo-shop u-flex u-row-between">
							<view class="u-flex">
								<u-icon name="map-fill" color="#4066F4" size="35"></u-icon>
								<view class="u-margin-left-10">{{item.city}}</view>
							</view>
							<view class="u-flex">
								<!-- <u-icon name="heart-fill" color="#FF5D39" size="35"></u-icon> -->
								<view class="u-margin-left-10"  v-if="(item.totalCollect+item.likeNum)">{{item.totalCollect+item.likeNum}}<text
										class="$u-type-info u-margin-left-10">收藏</text></view>
							</view>
						</view>
					</view>

					<view v-if="item.object">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.object.cover" :index="index">
						</u-lazy-load>
						<view class="demo-title" v-if="item.object.title">
							{{item.object.title}}
						</view>
						<view class="demo-title" v-if="item.object.goodsName">
							{{item.object.goodsName}}
						</view>
						<view class="demo-shop u-flex u-row-between" v-if="item.object.title">
							<view class="u-flex">
								<u-icon name="map-fill" color="#4066F4" size="35"></u-icon>
								<view class="u-margin-left-10">{{item.object.city}}</view>
							</view>
							<view class="u-flex">
								<!-- <u-icon name="heart-fill" color="#FF5D39" size="35"></u-icon> -->
								<view class="u-margin-left-10"  v-if="(item.totalCollect+item.likeNum)">{{item.totalCollect+item.likeNum}}<text
										class="$u-type-info u-margin-left-10">收藏</text></view>
							</view>
						</view>
					</view>
				</view>
			</template>
			<template v-slot:right="{rightList}">
				<view class="demo-warter" v-for="(item, index) in rightList" :key="index" @click="go(item)">
					<u-lazy-load threshold="-450" border-radius="10" :image="item.cover" :index="index"
						v-if="item.cover"></u-lazy-load>
					<view v-if="item.classifyName">
						<view class="u-font-weight u-margin-bottom-10 u-margin-top-10">
							{{item.title}}
						</view>
						<view>
							<u-icon name="bookmark-fill" color="#2979FF"></u-icon>
							<text class="u-font-xs  u-margin-left-10 $u-type-info">{{item.classifyName}}</text>
						</view>
					</view>
					<view v-if="item.city">
						<view class="demo-title">
							{{item.title}}
						</view>
						<view class="demo-shop u-flex u-row-between">
							<view class="u-flex">
								<u-icon name="map-fill" color="#4066F4" size="35"></u-icon>
								<view class="u-margin-left-10">{{item.city}}</view>
							</view>
							<view class="u-flex">
								<!-- <u-icon name="heart-fill" color="#FF5D39" size="35"></u-icon> -->
								
							</view>
						</view>
					</view>
					<view v-if="item.object">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.object.cover" :index="index">
						</u-lazy-load>
						<view class="demo-title" v-if="item.object.title">
							{{item.object.title}}
						</view>
						<view class="demo-title" v-if="item.object.goodsName">
							{{item.object.goodsName}}
						</view>
						<view class="demo-shop u-flex u-row-between" v-if="item.object.title">
							<view class="u-flex">
								<u-icon name="map-fill" color="#4066F4" size="35"></u-icon>
								<view class="u-margin-left-10">{{item.object.city}}</view>
							</view>
							<view class="u-flex">
								<!-- <u-icon name="heart-fill" color="#FF5D39" size="35"></u-icon> -->
								
							</view>
						</view>
					</view>
				</view>
			</template>
		</u-waterfall>

	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array
			},
			elseWay: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				loadStatus: 'loadmore',
				flowList: [],

			}
		},
		watch: {
			list: {
				immediate: true,
				handler(v) {

					this.addRandomData()
				}
			}
		},
		onHide() {


		},

		methods: {
			addRandomData() {
				this.flowList = [];
				for (let i = 0; i < this.list.length; i++) {
					let index = i;
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.idx = this.$u.guid();
					this.flowList.push(item);
				}
				this.$forceUpdate()
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			},
			go(item,) {

				if (item.url) {
					// uni.navigateTo({
					// 	url: '/pages/web/index?url=' + item.url
					// })
					this.$emit("poup", item)
				return
				}


				this.$emit("go", item)


			}
		}
	}
</script>



<style lang="scss" scoped>
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
</style>

<style lang="scss" scoped>
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>
</style>
